/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.chl.hajo.jsfs.bb;

import edu.chl.hajo.jsfs.mb.ShopBean;
import edu.chl.hajo.shop.core.Product;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import javax.inject.Inject;

import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.enterprise.context.SessionScoped;
import javax.faces.event.ActionEvent;
import javax.inject.Named;
import javax.validation.constraints.*;

/**
 *
 * @author hajo
 */
@Named("addProduct")
@RequestScoped  // NOTE enterprise package, else disaster!!!
public class AddProductBB {
     @NotNull
    @Size(min = 2, message = "Enter a real name")
    private String name;
        //@Digits(integer=2, fraction=0)
    @Min(value = 0, message = "Price must not be negative")
    private String price;
    @Inject 
    private ShopBean shop;

    public String save() {
        // Id generated by database
        Product p = new Product(name, Double.valueOf(price));
        shop.getProductCatalogue().add(p);
        return Navigation.PRODUCT_SUCCESS.toString();  // TODO
    }
    
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPrice() {
        return price;
    }

    public void setPrice(String price) {
        this.price = price;
    }
    
}
